package com.futao.springbootlearn20220224.event;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author futao
 * @date 2022/2/24
 */
@RestController
@RequestMapping("/event")
public class EventPublisher {

    @Autowired
    private ApplicationContext applicationContext;

    @GetMapping("/publish")
    public void publish(Long id, String username) {
        applicationContext.publishEvent(new UserRegisterEvent(this, new UserRegisterEvent.NewUser(id, username)));
    }
}
